package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "品牌管理")
@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {
    @Autowired
    private BaseTrademarkService baseTrademarkService;

    @GetMapping("/{page}/{limit}")
    public Result getTrademarkList(@PathVariable Long page, @PathVariable Long limit) {
        IPage<BaseTrademark> pageInfo = new Page<>(page, limit);
        IPage<BaseTrademark> pageModel = baseTrademarkService.getTrademarkList(pageInfo);
        return Result.ok(pageModel);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/remove/{id}")
    public Result deleteBaseTrademarkById(@PathVariable Long id) {
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    /**
     * 根据品牌Id 获取品牌对象
     */
    @GetMapping("get/{id}")
    public Result getBaseTrademarkById(@PathVariable Long id) {
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    /**
     * 修改
     */
    @PutMapping("update")
    public Result updateBaseTrademark(@RequestBody BaseTrademark baseTrademark) {
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    /**
     * 新增
     */
    @PostMapping("save")
    public Result saveBaseTrademark(@RequestBody BaseTrademark baseTrademark) {
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }
}
